package com.mapper;

import com.pojo.Report;
import com.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ReportMapper {

    @Select("select * from report where student_id in (select open_id from student where teacher_id = #{teacher_id}) order by subTime desc limit #{page},#{pagesize}")
    List<Report> getReportList(Integer teacher_id,Integer page,Integer pagesize);

    @Select("select count(*) from report where student_id in (select open_id from student where teacher_id = #{teacher_id})")
    Integer getTotal(Integer teacher_id);

    @Select("select * from report where id = #{id}")
    Report getById(Integer id);

    @Update("update report set score = #{score},remark = #{remark},state = 1,respond_time = NOW() where id = #{id}")
    void remark(Integer id,Double score,String remark);

    @Select("select * from student where open_id = #{open_id}")
    Student getStudentById(String open_id);

    @Select("select * from report where student_id = #{open_id} order by subTime desc limit #{page},#{pagesize}")
    List<Report> getStudentReports(String open_id,Integer page,Integer pagesize);

    @Insert("insert into report(student_id, state, startTime, endTime, subTime, conents, problem) value (#{student_id},0,#{startTime},#{endTime},#{subTime},#{conents},#{problem})")
    void add(String student_id, String startTime, String endTime, String subTime, String conents, String problem);

}